package com.stu.serive.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.stu.mapper.NoticeMapper;

import com.stu.pojo.Notice;
import com.stu.pojo.PageBean;
import com.stu.serive.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
@Slf4j
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;


    @Override
    public PageBean notice(Integer page, Integer pageSize,
                           String informationClass, String noticeKey,
                           LocalDate begin, LocalDate end) {
        //使用pageheleper
        //1.设置分页参数
        PageHelper.startPage(page, pageSize);
        //2.执行查询
        List<Notice> noticeList = noticeMapper.notice_select(
                informationClass, noticeKey, begin, end);//获得查询后的内容
        log.info("noticeList:{}",noticeList);
        Page<Notice> p = (Page<Notice>) noticeList; //将emplist转换类型为page并且封装在p中
        //3.封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }
}
